function testNum(x) {
     var res = /^(\d+)(\.\d?)?$/; 
    return res.test(x);
}
var VueObject = function () {
    return {
        kz: '克制',
        atk: 0,
        atk_add: 0,
        atk_del: 0,
        dmg_add1: 0,
        dmg_add2: 0,
        dmg_add3: 0,
        dmg_add4: 0,
        dmg_add5: 0,
        dmg_add6: 0,
        dmg_add7: 0,
        dmg_add8: 50,
        dmg_add9: 0,
        dmg_add10: 0,
        dmg_v: 0,
        dmg_v_cri: 0,
        dmg_def: 0,
        dmg_hit: 50,
        dmg_v_eva: 0,
        dmg_res: 0,
        dmg_res2: 0,
        dmg_idef:0,
        def_minus_1:0,
        dmg_idef_1:0,
        hit: 0,
        eva: 0,
        def_minus: 0,
        def: 0,
        enemy_eva: 0,
        enemy_hit: 0,
        def_pct_1:0,
        rs: '',
        hit_pct: 0,
        eva_pct: 0,
        def_pct: 0,
        enemy_eva_pct: 0,
        enemy_hit_pct: 0,
        boss_2: '',
        boss_data: 
        { 
            仲裁者A_红蜘蛛:
            {
                hp: 2070294,
                def: 3000,
                hit: 1501,
                eva: 1000,
                t:'机械'
            },
            仲裁者B_黄蜘蛛:
            {
                hp: 1867263,
                def: 1858,
                hit: 1501,
                eva: 3001,
                t:'机械'
            },
            突击怨妇:
            {
                hp: 1493862,
                def: 1736,
                hit: 2045,
                eva: 1203,
                t:'侵蚀体'
            },
            攻城怨妇:
            {
                hp: 2167361,
                def: 3500,
                hit: 1000,
                eva: 0,
                t:'侵蚀体'
            }, 
            暴君盾:
            {
                hp: 1416578,
                def: 3389,
                hit: 1973,
                eva: 1158 ,
                t:'侵蚀体'
            },
            暴君剑:
            {
                hp: 2007882,
                def: 747,
                hit: 1973,
                eva: 2317 ,
                t:'侵蚀体'
            },
            大主教:
            {
                hp: 1381745,
                def: 2132,
                hit: 1834,
                eva: 1442 ,
                t:'制裁者'
            },
            克隆骑士:
            {
                hp: 1065489,
                def: 1266,
                hit: 3592,
                eva: 482 ,
                t:'制裁者'
            },
            克隆皇帝:
            {
                hp: 1031495,
                def: 1634,
                hit: 1938,
                eva: 565 ,
                t:'制裁者+克隆集团'
            },
            大蛇:
            {
                hp: 1152466,
                def: 3650,
                hit: 4291,
                eva: 1608 ,
                t:'制裁者'
            },
            女高音:
            {
                hp: 2552578,
                def: 4474,
                hit: 2405,
                eva: 1084 ,
                t:'侵蚀体'
            },
            湖中骑士: {
                hp: 1549766,
                def: 1864,
                hit: 5292,
                eva: 1324,
                t:'侵蚀体'
            }, 
            
        } 
        ,
        boss: [
            {
                index: '0',
                name: '仲裁者A_红蜘蛛' 
            },
            {
                index: '1',
                name: '仲裁者B_黄蜘蛛' 
            },
            {
                index: '2',
                name: '突击怨妇' 
            },
            {
                index: '3',
                name: '攻城怨妇' 
            },
            {
                index: '4',
                name: '暴君盾' 
            },
            {
                index: '5',
                name: '暴君剑' 
            },
            {
                index: '6',
                name: '大主教' 
            },
            {
                index: '7',
                name: '克隆骑士' 
            },
            {
                index: '8',
                name: '克隆皇帝' 
            },
            {
                index: '9',
                name: '大蛇' 
            },
            {
                index: '10',
                name: '女高音' 
            },
            {
                index: '11',
                name: '湖中骑士' 
            },
        ],

    };

};


var VueFunc_PC = {
    boss2_change(xxxx) {
        var x = this.boss_data[this.boss_2];
        this.enemy_hit = x.hit;
        this.enemy_eva = x.eva;
        this.def = x.def; 
        this.hitcalc();
    },
    hitcalc() {
        this.hit_pct = (this.hit * 100 / (this.hit + 1500)).toFixed(4);
        this.eva_pct = (this.eva * 100 / (this.eva + 800)).toFixed(4); 
        this.def_pct = (this.def * 100 / (this.def + 999)).toFixed(4);
        this.enemy_eva_pct = (this.enemy_eva * 100 / (this.enemy_eva + 800)).toFixed(4);
        this.enemy_hit_pct = (this.enemy_hit * 100 / (this.enemy_hit + 1500)).toFixed(4);
        var Ndef=this.def * ((100 - this.def_minus) / 100 *(100-this.dmg_idef)/100);
        var Ndef_pct = (Ndef * 100 / (Ndef + 999)).toFixed(4);
        this.rs = '敌方防御数值为' + Ndef + ',防御减伤比率=' + Ndef_pct + '%\r\n';  
        /**
         * 命中Y=X/(X+1500)
         * 闪避Z=E/(E+800)
         * Y>=Z
         * 即X/(X+1500)>=Z
         * X>=Z*(X+1500)
         * X>=ZX+1500Z
         * X-ZX>=1500Z
         * (1-Z)X>=1500Z
         * X>=1500Z/(1-Z)
         */
        this.rs += '我方需要命中数值' + (1500 * this.enemy_eva_pct / 100 / (1 - this.enemy_eva_pct / 100)).toFixed(4) + '以达到必中\r\n';
        var eva_50 = this.enemy_eva * 0.5;
        var eva_50pct = (eva_50 * 100 / (eva_50 + 800)).toFixed(4);
        console.log('eav50=' + eva_50 + ',pct=' + eva_50pct+'%');
        this.rs += '我方在企业/足球妹减50%闪避下,需要命中数值' + (1500 * eva_50pct / 100 / (1 - eva_50pct / 100)).toFixed(4) + '以达到必中\r\n'; 

        this.rs += '我方前排需要闪避数值' + (800 * this.enemy_hit_pct / 100 / (1 - this.enemy_hit_pct / 100)).toFixed(4) + '以防止BOSS必中\r\n';
    },
    dmg_idef_1_change(x)
    {
        if (!testNum(x)) {
            this.dmg_idef_1 = 0;
        } else {
            this.dmg_idef_1 = parseFloat(x);
        }
        this.calcData();
    },
    def_minus_1_change(x)
    {
        if (!testNum(x)) {
            this.def_minus_1 = 0;
        } else {
            this.def_minus_1 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_idef_change(x)
    {
        if (!testNum(x)) {
            this.dmg_idef = 0;
        } else {
            this.dmg_idef = parseFloat(x);
        }
        this.hitcalc();
    },
    dmg_res2_change(x) {
        if (!testNum(x)) {
            this.dmg_res2 = 0;
        } else {
            this.dmg_res2 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_res_change(x) {
        if (!testNum(x)) {
            this.dmg_res = 0;
        } else {
            this.dmg_res = parseFloat(x);
        }
        this.calcData();
    },
    enemy_hit_change(x) {
        if (!testNum(x)) {
            this.enemy_hit = 0;
        } else {
            this.enemy_hit = parseFloat(x);
        }
        this.hitcalc();
    }, 
    enemy_eva_change(x) {
        if (!testNum(x)) {
            this.enemy_eva = 0;
        } else {
            this.enemy_eva = parseFloat(x);
        }
        this.hitcalc();
    },
    def_change(x) {
        if (!testNum(x)) {
            this.def = 0;
        } else {
            this.def = parseFloat(x);
        }
        this.hitcalc();
    },
    def_minus_change(x) { 
            if (!testNum(x)) {
                this.def_minus = 0;
            } else {
                this.def_minus = parseFloat(x);
        }
        this.hitcalc();
    },
    hit_change(x) {
        if (!testNum(x)) {
            this.hit = 0;
        } else {
            this.hit = parseFloat(x);
        }
        this.hitcalc();
    }, 
    eva_change(x) {
        if (!testNum(x)) {
            this.eva = 0;
        } else {
            this.eva = parseFloat(x);
        }
        this.hitcalc();
    },  
    dmg_hit_change(x) {
        if (!testNum(x)) {
            this.dmg_hit = 0;
        } else {
            this.dmg_hit = parseFloat(x);
        }
        this.calcData();
    },
    dmg_def_change(x) {
        if (!testNum(x)) {
            this.dmg_def = 0;
        } else {
            this.dmg_def = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add1_change(x) { 
        if (!testNum(x)) {
            this.dmg_add1 = 0;
        } else {
            this.dmg_add1 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add2_change(x) { 
        if (!testNum(x)) {
            this.dmg_add2 = 0;
        } else {
            this.dmg_add2 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add3_change(x) { 
        if (!testNum(x)) {
            this.dmg_add3 = 0;
        } else {
            this.dmg_add3 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add4_change(x) {
        var isN = testNum(x);
        if (!testNum(x)) {
            this.dmg_add4 = 0;
        } else {
            this.dmg_add4 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add5_change(x) { 
        if (!testNum(x)) {
            this.dmg_add5 = 0;
        } else {
            this.dmg_add5 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add6_change(x) { 
        if (!testNum(x)) {
            this.dmg_add6 = 0;
        } else {
            this.dmg_add6 = parseFloat(x);
        }
        this.calcData();
    },

    dmg_add6_change(x) { 
        if (!testNum(x)) {
            this.dmg_add6 = 0;
        } else {
            this.dmg_add6 = parseFloat(x);
        }
        this.calcData();
    },

    dmg_add7_change(x) { 
        if (!testNum(x)) {
            this.dmg_add7 = 0;
        } else {
            this.dmg_add7 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add8_change(x) { 
        if (!testNum(x)) {
            this.dmg_add8 = 0;
        } else {
            this.dmg_add8 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add9_change(x) { 
        if (!testNum(x)) {
            this.dmg_add9 = 0;
        } else {
            this.dmg_add9 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add10_change(x) { 
        if (!testNum(x)) {
            this.dmg_add10 = 0;
        } else {
            this.dmg_add10 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add11_change(x) { 
        if (!testNum(x)) {
            this.dmg_add11 = 0;
        } else {
            this.dmg_add11 = parseFloat(x);
        }
        this.calcData();
    },
    dmg_add12_change(x) { 
        if (!testNum(x)) {
            this.dmg_add12 = 0;
        } else {
            this.dmg_add12 = parseFloat(x);
        }
        this.calcData();
    },
 
    atk_add_change(x) { 
        if (!testNum(x)) {
            this.atk_add = 0;
        } else {
            this.atk_add = parseFloat(x);
        }
        this.calcData();
    }, atk_del_change(x) { 
        if (!testNum(x)) {
            this.atk_del = 0;
        } else {
            this.atk_del = parseFloat(x);
        }
        this.calcData();
    },
    atk_change(x) {
        if (!testNum(x)) {
            this.atk = 0;
        } else {
            this.atk = parseFloat(x);
        }
        this.calcData();
    },
    kz_change(x) {

        this.calcData();
    },
    checkData() {

    },
    calcData() { 
        var dmg1 = (this.atk) * (100 + (this.atk_add) - (this.atk_del)) / 100;

        var def=this.dmg_def*(100-this.def_minus_1)/100*(100-this.dmg_idef_1)/100; 
        this.def_pct_1 = (def * 100 / (def + 999)).toFixed(4);

        var res1 = (100 + this.dmg_add1 + this.dmg_add2 + this.dmg_add3 + this.dmg_add4 - this.dmg_res) / 100 * (100 - this.def_pct_1) / 100;
        if (res1 < 0.2) res1 = 0.2;
        console.log(res1);
        var res2 = (100 + this.dmg_add6 - this.dmg_res2) / 100;
        if (res2 < 0.5) res2 = 0.5;
        dmg1 = dmg1 * res1 * res2 * (this.dmg_add7 + 100) / 100;
        if (this.kz === '克制') {
            dmg1 = dmg1 + dmg1 * 0.3 * (this.dmg_add5 + 100) / 100;
        } else if (this.kz === '被克制') {
            dmg1 = dmg1 * 0.7;
        } else if (this.kz === '不克制') {

        }
        this.dmg_v = Math.round( dmg1);
        this.dmg_v_cri = Math.round(dmg1 * (this.dmg_add8 + 100) / 100);
        this.dmg_v_eva = Math.round(this.dmg_v * (this.dmg_hit+10)/100);
        
    },
    CloseAllPages() {

    },
    handleSelect(key, keyPath) {
    },
}; 

new Vue({
    el: '#app',
    data: VueObject,
    methods: VueFunc_PC
})